#include "world.h"

World::World(void)
{
	physicsCalc = new PhysicsCalc();
	
	/* riserva 50 elementi, comodo perche' altrimenti e' inefficiente = ogni modifica al vettore
	 * comporta il riallocamento delle componenti :/
	 */
	entities.reserve(50);
}

World::~World(void)
{
	//
}

void World::addForce(WorldPlayer *player, Vector2D force)
{
	getEntity(0)->addForce(Vector2D(0.0f,80.0f));
}

void World::addEntity(WorldEntity* entity)
{
	entities.push_back(entity);
}

void World::removeEntity(WorldEntity *entity)
{
	for (unsigned int i = 0; i < entities.size(); ++i)
	{
		if (entities[i] == entity)
			entities.erase(entities.begin()+i);
	}
}

int World::getEntityCount(void)
{
	return entities.size();
}

WorldEntity *World::getEntity(int i)
{
	return ((WorldEntity*)entities[i]);
}

void World::updateWorld(double delta)
{
	physicsCalc->updateEntities(this, delta);
}

void World::shootProjectile(int type, float x, float y, Vector2D vel, Vector2D acc, Vector2D gravity, WorldPlayer *owner)
{
	WorldProjectile *projectile = new WorldProjectile(x,y, type, vel, acc, gravity);
	
	projectile->owner = owner;
	
	addEntity(projectile);
}
